﻿using System;

namespace Loki.Utils
{
    /// <summary>
    /// Base class.
    /// </summary>
    /// <remarks>Provides log and error management methods.</remarks>
    public abstract class LokiObject : LoggableObject
    {
        #region Exception handling methods

        /// <summary>
        /// Builds the error.
        /// </summary>
        /// <param name="P_Message">The message.</param>
        protected T BuildError<T>(string P_Message) where T : Exception
        {
            return LokiServices.Errors.BuildError<T>(P_Message, Log);
        }

        /// <summary>
        /// Builds the error.
        /// </summary>
        /// <param name="P_Message">The message.</param>
        /// <param name="P_InnerException">The inner exception.</param>
        protected T BuildError<T>(string P_Message, Exception P_InnerException) where T : Exception
        {
            return LokiServices.Errors.BuildError<T>(P_Message, Log, P_InnerException);
        }

        /// <summary>
        /// Builds the error with the specified format paramters.
        /// </summary>
        /// <param name="P_Message">The message.</param>
        /// <param name="P_Params">The params.</param>
        protected T BuildErrorFormat<T>(string P_Message, params object[] P_Params) where T : Exception
        {
            return LokiServices.Errors.BuildErrorFormat<T>(P_Message, Log, P_Params);
        }

        /// <summary>
        /// Builds the error with the specified format paramters.
        /// </summary>
        /// <param name="P_Message">The message.</param>
        /// <param name="P_InnerException">The inner exception.</param>
        /// <param name="P_Params">The params.</param>
        protected T BuildErrorFormat<T>(string P_Message, Exception P_InnerException, params object[] P_Params) where T : Exception
        {
            return LokiServices.Errors.BuildErrorFormat<T>(P_Message, Log, P_InnerException, P_Params);
        }

        /// <summary>
        /// Logs the specified error.
        /// </summary>
        /// <param name="P_Message">The error message.</param>
        /// <param name="P_InnerException">The exception.</param>
        /// <param name="P_Params">Formatting parameters.</param>
        protected void LogErrorCode(string P_Message, Exception P_InnerException, params object[] P_Params)
        {
            LokiServices.Errors.LogError(P_Message, Log, P_InnerException, P_Params);
        }
        #endregion
    }
}
